package com.vastcom.sbjwt.service.impl;

import com.vastcom.sbjwt.model.User;
import com.vastcom.sbjwt.repository.UserRepository;
import com.vastcom.sbjwt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public User findByid(Long id) throws UsernameNotFoundException {
        User u=userRepository.findOne(id);
        return u;
    }

    @Override
    public User findByUsername(String name) throws AccessDeniedException {
        User u=userRepository.findUserByUsername(name);

        return u;
    }

    @Override
    public List<User> findAll() throws AccessDeniedException {

        List<User> result=userRepository.findAll();
        return result;
    }
}
